package com.android.lovingpet.mine.setting;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.lovingpet.R;
import com.android.lovingpet.SplashActivity;
import com.android.lovingpet.base.BaseFragment;
import com.android.lovingpet.common.userlist.UserListActivity;
import com.android.lovingpet.mine.setting.about.AboutFragment;
import com.android.lovingpet.mine.setting.accountsecurity.AccountSecurityFragment;
import com.android.lovingpet.mine.setting.message.MessageSettingFragment;
import com.android.lovingpet.util.Utility;

public class SettingFragment extends BaseFragment<ISettingContract.View, SettingPresenter> implements View.OnClickListener, ISettingContract.View {

    @Override
    protected int setContentView() {
        return R.layout.fragment_setting;
    }

    @Override
    protected void onCreateView(View view) {
        view.findViewById(R.id.ll_set_message).setOnClickListener(this);
        view.findViewById(R.id.ll_set_about).setOnClickListener(this);
        view.findViewById(R.id.ll_set_account).setOnClickListener(this);
        view.findViewById(R.id.ll_set_blacklist).setOnClickListener(this);
        view.findViewById(R.id.ll_set_logout).setOnClickListener(this);
        ((TextView) view.findViewById(R.id.tv_title)).setText("设置");
    }

    @Override
    public SettingPresenter createPresenter() {
        return new SettingPresenter();
    }

    @Override
    public ISettingContract.View createView() {
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_set_message:
                getFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(
                                R.anim.slide_right_in,
                                R.anim.slide_left_out,
                                R.anim.slide_left_in,
                                R.anim.slide_right_out)
                        .replace(R.id.fragment_mine_setting, new MessageSettingFragment())
                        .addToBackStack(null)
                        .commit();
                break;

            case R.id.ll_set_about:
                getFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(
                                R.anim.slide_right_in,
                                R.anim.slide_left_out,
                                R.anim.slide_left_in,
                                R.anim.slide_right_out)
                        .replace(R.id.fragment_mine_setting, new AboutFragment())
                        .addToBackStack(null)
                        .commit();
                break;

            case R.id.ll_set_account:
                getFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(
                                R.anim.slide_right_in,
                                R.anim.slide_left_out,
                                R.anim.slide_left_in,
                                R.anim.slide_right_out)
                        .replace(R.id.fragment_mine_setting, new AccountSecurityFragment())
                        .addToBackStack(null)
                        .commit();
                break;

            case R.id.ll_set_blacklist:
                Intent blacklist = new Intent(getActivity(), UserListActivity.class);
                blacklist.putExtra(UserListActivity.TITLE_KEY, UserListActivity.TITLE_BLACKLIST);
                blacklist.putIntegerArrayListExtra(UserListActivity.IDS_KEY, null);
                startActivity(blacklist);
                break;

            case R.id.ll_set_logout:
                getPresenter().logout();
                Utility.setJSessionId("");
                Intent intent = new Intent(getActivity(), SplashActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                break;

            default:
                break;
        }
    }
}
